<?php

namespace Home\Controller;

use Think\Controller;
use Home\Service\UserService;
use Home\Common\FIdConst;
use Home\Service\GOBillService;
use Home\Service\SOBillService;

/**
 * Controller
 *
 * @author 李静波
 *        
 */
class GoodsownerBillController extends PSIBaseController {

	
	/**
	 * 订单- 主页面
	 */
	public function billIndex() {
		$us = new UserService();
	
		if ($us->hasPermission(FIdConst::GOODSOWNER_MANAGER)) {
			$this->initVar();
	
			$this->assign("title", "货权转移订单");

			// 			$this->assign("pAddCategory",
			// 					$us->hasPermission(FIdConst::SUPPLIER_CATEGORY_ADD) ? 1 : 0);
			// 			$this->assign("pEditCategory",
			// 					$us->hasPermission(FIdConst::SUPPLIER_CATEGORY_EDIT) ? 1 : 0);
			// 			$this->assign("pDeleteCategory",
			// 					$us->hasPermission(FIdConst::SUPPLIER_CATEGORY_DELETE) ? 1 : 0);
			// 			$this->assign("pAddGoodsowner", $us->hasPermission(FIdConst::SUPPLIER_ADD) ? 1 : 0);
			// 			$this->assign("pEditGoodsowner", $us->hasPermission(FIdConst::SUPPLIER_EDIT) ? 1 : 0);
			// 			$this->assign("pDeleteGoodsowner", $us->hasPermission(FIdConst::SUPPLIER_DELETE) ? 1 : 0);
	
			$this->display();
		} else {
			$this->gotoLoginPage("/Home/GoodsownerBill/billIndex");
		}
	}

	/**
	 * 获得货权转移单的信息
	 */
	public function goBillInfo() {
		if (IS_POST) {
			$params = array(
					"id" => I("post.id")
			);
			
			$gob = new GOBillService();
			$this->ajaxReturn($gob->goBillInfo($params));
		}
	}

	/**
	 * 新建或编辑货权转移单
	 */
	public function editGOBill() {
		if (IS_POST) {
			$params = array(
					"jsonStr" => I("post.jsonStr")
			);
			
			$gob = new GOBillService();
			$this->ajaxReturn($gob->editGOBill($params));
		}
	}

	/**
	 * 货权转移单主表信息列表
	 */
	public function getGobillList() {
		if (IS_POST) {
			$params = array(
					"billStatus" => I("post.billStatus"),
					"ref" => I("post.ref"),
					"fromDT" => I("post.fromDT"),
					"toDT" => I("post.toDT"),
					"warehouseId" => I("post.warehouseId"),
					"customerId" => I("post.customerId"),
					"fromGoodsownerId" => I("post.fromGoodsownerId"),
					"toGoodsownerId" => I("post.toGoodsownerId"),
					"receivingType" => I("post.receivingType"),
					"sn" => I("post.sn"),
					"page" => I("post.page"),
					"start" => I("post.start"),
					"limit" => I("post.limit")
			);
			
			$gob = new GOBillService();
			$this->ajaxReturn($gob->getGobillList($params));
		}
	}
	

	/**
	 * 删除货权转移订单
	 */
	public function deleteGOBill() {
		if (IS_POST) {
			$params = array(
					"id" => I("post.id")
			);
			
			$ps = new GOBillService();
			$this->ajaxReturn($ps->deleteGOBill($params));
		}
	}

	/**
	 * 审核货权转移订单
	 */
	public function commitGOBill() {
		if (IS_POST) {
			$params = array(
					"id" => I("post.id")
			);
			
			$ps = new GOBillService();
			$this->ajaxReturn($ps->commitGOBill($params));
		}
	}

	/**
	 * 取消货权转移订单审核
	 */
	public function cancelConfirmGOBill() {
		if (IS_POST) {
			$params = array(
					"id" => I("post.id")
			);
			
			$ps = new GOBillService();
			$this->ajaxReturn($ps->cancelConfirmGOBill($params));
		}
	}
}